(SST) ShlWAPI.pas Version 1.08

Developer Reference
(SST)ShlWAPI StrStrI Function
Performs a case-insensitive search for a (sub-)string in a string.
Scope
Global (i.e. this function can be called/accessed from code in any unit that includes/uses (SST)ShlWAPI.pas).
Syntax
function StrStrI(lpFirst : LPCSTR; lpSrch : LPCSTR) : LPSTR;
lpFirst [in] Depending on which version of the function is called, a pointer to the null-terminated, ANSI or Unicode string, in which to search for the (sub-)string specified in parameter lpSrch.
lpSrch [in] Depending on which version of the function is called, a pointer to the null-terminated, ANSI or Unicode (sub-)string to search for.
Return Values
If the string specified in lpFirst contains one or more copies of the string to search for (lpSrch), and the string to search differs from the sub-string to search for only in case, (e.g. string to be searched: "The quick brown fox jumped over the fence, but the quick brown fox did not ..." and string to search for: "THE qUICK BROWN Fox ") the function returns a pointer to the first occurrence of the sub-string within lpFirst. If an invalid parameter was specified (e.g. a NIL pointer or an empty string), or the function was unable to find the sub-string (lpSrch) in lpFirst, it returns NIL (= 0).
Remarks
StrStr and StrStrI seem to have been introduced in the very first ShlWAPI.dll version (4.71) and continue to be supported under Windows 10.
Example
PROCEDURE TForm4.TestShlWAPIStrStrI(Sender : TObject); VAR strtosrchfor : STRING; VAR txttosearch : STRING; VAR apiretptr : POINTER; VAR newinfoline : STRING; BEGIN strtosrchfor := ''; txttosearch := ''; apiretptr := NIL; newinfoline := ''; strtosrchfor := 'FoX'; //Compare to the first parameter of the first example in the StrStr sample code txttosearch := 'The quick, brown fox jumped over the fence and hid in the fox burrow'; newinfoline := 'StrStr called with lpFirst (without the quotation marks) = "' + txttosearch + '" and lpSrch = ' + strtosrchfor; Memo1.Lines.Add(newinfoline); apiretptr := StrStrI(PChar(txttosearch), PChar(strtosrchfor)); IF apiretptr <> NIL THEN newinfoline := 'StrStrI returned a pointer to "' + PChar(apiretptr) + '"' ELSE newinfoline := 'StrStrI returned NIL !'; Memo1.Lines.Add(newinfoline); strtosrchfor := 'FENCE'; //Note, that the word to search for is all in upper case txttosearch := 'The quick, brown fox jumped over the fence and hid in the fox burrow'; newinfoline := 'StrStrI called with lpFirst (without the quotation marks) = "' + txttosearch + '" and lpSrch = ' + strtosrchfor; Memo1.Lines.Add(newinfoline); apiretptr := StrStrI(PChar(txttosearch), PChar(strtosrchfor)); IF apiretptr <> NIL THEN newinfoline := 'StrStrI returned a pointer to "' + PChar(apiretptr) + '"' ELSE newinfoline := 'StrStrI returned NIL !'; Memo1.Lines.Add(newinfoline); strtosrchfor := ''; //Note, that the text to search for is an empty string txttosearch := 'The quick, brown fox jumped over the fence and hid in the fox burrow'; newinfoline := 'StrStrI called with lpFirst (without the quotation marks) = "' + txttosearch + '" and lpSrch = ' + strtosrchfor; Memo1.Lines.Add(newinfoline); apiretptr := StrStrI(PChar(txttosearch), PChar(strtosrchfor)); IF apiretptr <> NIL THEN newinfoline := 'StrStrI returned a pointer to "' + PChar(apiretptr) + '"' ELSE newinfoline := 'StrStrI returned NIL !'; Memo1.Lines.Add(newinfoline); txttosearch := 'The quick, brown fox jumped over the fence and hid in the fox burrow'; newinfoline := 'StrStrI called with lpFirst (without the quotation marks) = "' + txttosearch + '" and lpSrch = NIL'; Memo1.Lines.Add(newinfoline); apiretptr := StrStrI(PChar(txttosearch), NIL); //Note that we're passing a null pointer to the function IF apiretptr <> NIL THEN newinfoline := 'StrStrI returned a pointer to "' + PChar(apiretptr) + '"' ELSE newinfoline := 'StrStrI returned NIL !'; Memo1.Lines.Add(newinfoline); Memo1.Lines.Add(''); END;
When run, the above code produces the following output:
StrStr called with lpFirst (without the quotation marks) = "The quick, brown fox jumped over the fence and hid in the fox burrow" and lpSrch = FoX StrStrI returned a pointer to "fox jumped over the fence and hid in the fox burrow" StrStrI called with lpFirst (without the quotation marks) = "The quick, brown fox jumped over the fence and hid in the fox burrow" and lpSrch = FENCE StrStrI returned a pointer to "fence and hid in the fox burrow" StrStrI called with lpFirst (without the quotation marks) = "The quick, brown fox jumped over the fence and hid in the fox burrow" and lpSrch = StrStrI returned NIL ! StrStrI called with lpFirst (without the quotation marks) = "The quick, brown fox jumped over the fence and hid in the fox burrow" and lpSrch = NIL StrStrI returned NIL !
Requirements
Unit: Declared and imported in (SST)ShlWAPI.pas
Library: (SST)ShlWAPI.dcu/(SST)ShlWAPI.obj
Unicode: Implemented as ANSI (StrStrI and StrStrIA) and Unicode (StrStrIW) functions.
Min. ShlWAPI.dll version according to MS SDK doc.: 4.71
Min. ShlWAPI.dll version based on SST research: 4.71
Min. OS version(s) according to Microsoft SDK doc.: Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0
Min. OS version(s) according to SST research.: Windows NT 4.0 with IE 4.0, Windows 95 with IE 4.0, Windows 98, Windows 2000 and later
See Also
StrStr, StrStrNW, StrStrNIW, StrCSpn, StrCSpnI.
 
Windows APIs: StrStrI, StrStr, StrStrNW, StrStrNIW, StrCSpn, StrCSpnI.


Document/Contents version 1.01
Page/URI last updated on 07.12.2023
 
Copyright © Stoelzel Software Technologie (SST) 2010 - 2015
Suggestions and comments mail to:
webmaster@stoelzelsoftwaretech.com